import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.ParserConfig;
import sun.net.www.protocol.http.HttpURLConnection;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class TestRequest {



    private static final String areaID = "5fdf56a3e2c1ee0001a52e49";
    private static final String publishUserID = "607457dffe0f450001605daf";

    public static void main(String[] args) throws IOException, InterruptedException {


        for (int i = 1; i <= 247; i++) {

            String u = "https://api.github.com/repos/webVueBlog/interview-answe/issues?per_page=1&page=" + i;

            URL url = new URL(u);

            URLConnection httpURLConnection = url.openConnection();
            InputStream inputStream = httpURLConnection.getInputStream();

            ByteArrayOutputStream outputStream = new ByteArrayOutputStream(10 * 1024);

            int index = 0;
            byte[] buffer = new byte[1024];
            while ((index = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, index);
            }

            String val = outputStream.toString("UTF-8");
            String desc = val.substring(1, val.length() - 1);

            JSONObject value = JSON.parseObject(desc);
            String title = value.getString("title");

            JSONObject obj = new JSONObject();

            obj.put("areaID", areaID);
            obj.put("publishUserID", publishUserID);
            obj.put("content", "");
            obj.put("questionExplanation", new JSONArray());
            JSONArray tag = new JSONArray();

            obj.put("tagID", tag);
            obj.put("createDate", "2021-04-12T22:18:23.913Z");
            obj.put("updateDate", "2021-04-12T22:18:23.913Z");
            obj.put("deleteDate", "");
            obj.put("state", "onlist");
            obj.put("title", title);

            System.out.println(obj.toJSONString());

            Thread.sleep(1000L);
        }

    }


}
